﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace PowerBooking.RSE.Utility.Helpers
{
    /// <summary>
    /// Http辅助类
    /// </summary>
    public class HttpHelper
    {
        private const string UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17";
        private const string ContentType = "text/html; charset=utf-8";

        public static string Get(string url)
        {
            var responseString = string.Empty;
            try
            {
                var request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "Get";
                request.ContentType = ContentType;
                request.UserAgent = UserAgent;
                using (var streamReader = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.UTF8))
                {
                    responseString = streamReader.ReadToEnd();
                }
            }
            catch (Exception exception)
            {
                ExceptionHelper.WriteFileLog(exception);
            }
            return responseString;
        }
    }
}
